package susebs.pb.travel_server.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import susebs.pb.travel_server.domain.NavigationResponse;
import susebs.pb.travel_server.domain.PageDto;
import susebs.pb.travel_server.domain.Result;
import susebs.pb.travel_server.entity.Landmarks;
import susebs.pb.travel_server.service.HotelsService;
import susebs.pb.travel_server.service.LandmarksService;
import susebs.pb.travel_server.service.NavigationsService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 *
 */
@RestController
@RequestMapping("/hotels")
@CrossOrigin
public class HotelsController {
    @Resource
    private HotelsService hotelsService;
    @Resource
    private LandmarksService landmarksService;
    @Resource
    private NavigationsService navigationsService;

    /**
     * 分页查询
     * @param pageDto 分页请求实体，仅包含酒店实体+分页数据
     * @return 包含图片的酒店列表
     */
    @PostMapping("/queryByPage")
    public Result queryByPage(@RequestBody PageDto pageDto){
        PageInfo list = hotelsService.queryAllHotelsByPage(pageDto);
        if(list.getList().isEmpty())return Result.buildFail("未查到相关信息！");
        ArrayList res = navigationsService.getListsAndPics(list.getList());
        return Result.buildSuccess(res);
    }


    /**
     * 酒店附近的景点
     * 通过酒店的城市字段，为pageDto设置设置景区城市参数，完成相关的查询、分页、结果的重组与集合
     * @param pageDto 分页请求实体，仅包含酒店实体+分页数据
     * @return 酒店附近的含图片的景点列表
     */
    @PostMapping("/hotelNearby")
    public Result hotelNearby(@RequestBody PageDto pageDto){
        String hotelCity = pageDto.getHotels().getCity();

        //设置请求参数
        Landmarks params = new Landmarks();
        params.setCity(hotelCity);
        pageDto.setLandmarks(params);

        //发起请求
        List list = landmarksService.queryAllLmsByPage(pageDto).getList();
        ArrayList res = navigationsService.getListsAndPics(list);

        return Result.buildSuccess(res);
    }

    //管理
    //删
    @GetMapping("/deleteById")
    public Result deleteById(Long hotelId){
        boolean delete = hotelsService.deleteById(hotelId);
        if(delete)return Result.buildSuccess();
        return Result.buildFail("删除失败！");
    }


























}
